package com.menchao.carsales.controller;

import com.menchao.carsales.common.http.ResponseData;
import com.menchao.carsales.pojo.Employee;
import com.menchao.carsales.service.IEmployeeService;
import com.menchao.carsales.vo.EmployeeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.function.ServerResponse;

import java.util.Map;

/**
 * Porject: carsales
 * Date: 2021/7/27
 * Author: menchao
 * Description:  增加雇员
 */

@RestController
@RequestMapping("employee")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;


    /**
     * 添加雇员
     * @param employee
     * @return
     */
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public ResponseData  addEmployee(@RequestBody Employee employee){

        System.out.println("employee add: " + employee.toString());
        return employeeService.addEmployee(employee);
    }


    /**
     * 获取雇员列表
     * @param employeeQuery
     * @return
     */
    @RequestMapping(value = "getList", method = RequestMethod.GET)
    public ResponseData getList(  EmployeeQuery employeeQuery) {
        System.out.println("getList : " + employeeQuery.toString());
        return employeeService.getList(employeeQuery);
    }

    /*
    更新雇员信息
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public ResponseData update(@RequestBody Employee employee) {

        return employeeService.updateEmployee(employee);
    }

    /**
     * 删除雇员
     * @return
     */
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public ResponseData deleteEmployee(@RequestBody Employee employee){
        return  employeeService.deleteEmployee(employee);
    }

}
